import os
import sys

def main():
	args = sys.argv
	
	if (len(args) < 2):
		print "not enough arguments"
		return
	
	#init flie names
	ImageFileName = args[1] + ".cin.img"
	SceneFileName = args[1] + ".cin"
	EXTracksName = "EXtracks" + args[1] + ".out"
	EXIamgeName = "EXimages" + args[1] + ".out"
	EXtransformsName = "EXtransforms" + args[1] + ".out"
	
	#running exporter
	os.system("bin\\ExportBundler.exe list.txt --options_file options.txt")
	
	#renaming outputs
	os.rename("EXimages.out", EXIamgeName)
	os.rename("EXtracks.out", EXTracksName)
	os.rename("EXtransforms.out", EXtransformsName)
	
	
	#writing image file
	ListFile = open("list.txt", "r")
	ImageFile = open(ImageFileName, "w")
	ListFileLines = ListFile.readlines()
	ImageFile.write("{0}".format(len(ListFileLines)) + "\n")
	for line in ListFileLines:
		splittedLine = line.split()
		ImageLoc = splittedLine[0]
		winImageLoc = ImageLoc.replace("/", "\\")
		ImageFile.write(winImageLoc + "\n")
		
	ListFile.close()
	ImageFile.close()
	
	#writing scene file
	SceneFile = open(SceneFileName, "w")
	SceneFile.write(ImageFileName + "\n")
	SceneFile.write(EXIamgeName + "\n")
	SceneFile.write(EXTracksName + "\n")
	SceneFile.write(EXtransformsName + "\n")
	SceneFile.close
	
main()